package com.xuyiwei.mayi.test;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import jdk.nashorn.internal.scripts.JO;

/**
 * Created by xuyiwei on 2019/4/13.
 */
public class Jsontest1 {
    public static void main(String[] args) {
        String jsonTest = "{\n" +
                "    \"id\": \"10\",\n" +
                "    \"name\": \"每特教育\",\n" +
                "    \"items\": [\n" +
                "        {\n" +
                "            \"itemId\": \"20\",\n" +
                "            \"itemName\": \"蚂蚁课堂\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"itemId\": \"21\",\n" +
                "            \"itemName\": \"每特学院\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";
        JSONObject object =  JSONObject.parseObject(jsonTest);
        System.out.println(object.getString("id"));
        System.out.println(object.getString("name"));

        JSONArray array = object.getJSONArray("items");
        for(int i=0;i<array.size();i++){
            JSONObject ob = array.getJSONObject(i);
            System.out.println(ob.getString("itemId"));
            System.out.println(ob.getString("itemName"));
        }

        System.out.println(JSONObject.toJSONString(object));
    }
}
